var X = Object.defineProperty;
var Y = (t, e, s) => e in t ? X(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
var f = (t, e, s) => (Y(t, typeof e != "symbol" ? e + "" : e, s), s);
var C = Object.defineProperty, O = (t, e, s) => e in t ? C(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s, P = (t, e, s) => (O(t, typeof e != "symbol" ? e + "" : e, s), s);
const T = new class {
  constructor() {
    P(this, "event", /* @__PURE__ */ new Map());
  }
  /**
   * @description: 通知
   * @param {string} id ID
   * @param {...array} parameter 参数
   * @return {void}
   */
  emit(t, ...e) {
    const s = this.event.get(t);
    s && s.forEach((i) => i(...e));
  }
  /**
   * @description: 监听
   * @param {string} id ID
   * @param {Func} func 回调
   * @return {void}
   */
  on(t, e) {
    var s;
    this.event.has(t) || this.event.set(t, []), (s = this.event.get(t)) == null || s.push(e);
  }
  /**
   * @description: 取消监听
   * @param {string} id ID
   * @param {Func} func 回调
   *
   * 取消所有的订阅 都不传递
   *
   * 针对名称下所有的函数取消订阅 只传递id
   *
   * 针对名称和函数取消订阅 传递id和func
   *
   * @return {void}
   */
  off(t, e) {
    if (!t && !e) {
      this.event.clear();
      return;
    }
    if (!t)
      return;
    const s = this.event.get(t);
    if (!s)
      return;
    if (!e) {
      this.event.delete(t);
      return;
    }
    const i = [];
    for (let a = 0; a < s.length; a++)
      s[a].toString() !== e.toString() && i.push(s[a]);
    i.length > 0 ? this.event.set(t, i) : this.event.delete(t);
  }
  /**
   * @description: 查询已订阅的名称数量
   * @param {string} id ID
   *
   * 查询已订阅的名称数量 不传递id
   *
   * 查询某个名称下的订阅数量 传递id
   *
   * @return {number}
   */
  getSize(t) {
    if (typeof t != "string")
      return this.event.size;
    const e = this.event.get(t);
    return e ? e.length : 0;
  }
}();
class A {
  constructor() {
    P(this, "task", []), P(this, "status", !1);
  }
  /**
   * 加入新的任务
   */
  push(e) {
    this.task.push(e), this.execute();
  }
  /**
   * 获取当前任务数量
   */
  getSize() {
    return this.task.length;
  }
  /**
   * 执行下一个任务
   */
  execute() {
    this.task.length <= 0 || this.status || (this.status = !0, this.task[0](() => {
      this.status = !1, this.task.splice(0, 1), this.execute();
    }));
  }
}
function $(t, e = 200, s = !1) {
  let i;
  return function() {
    i || (s ? (t.apply(null, arguments), i = globalThis.setTimeout(() => i = void 0, e)) : i = globalThis.setTimeout(() => {
      t.apply(null, arguments), i = void 0;
    }, e));
  };
}
function j(t, e = 200, s = !1) {
  let i;
  return function() {
    i || (s && t.apply(null, arguments), i = globalThis.setTimeout(() => {
      s || t.apply(null, arguments), i = void 0;
    }, e));
  };
}
async function z(t = 0) {
  if (!(typeof t != "number" || t <= 0))
    return new Promise(function(e) {
      setTimeout(e, t);
    });
}
const o = function(t) {
  const e = Object.prototype.toString.call(t).replace(/\[|]|object|\s/g, "").toLocaleLowerCase();
  return e !== "number" ? e : isNaN(t) ? "nan" : e;
}, g = {
  /**
   * @description: 获取某个数据类型
   * @param {any} v 数据
   * @return {DataType} 数据类型
   */
  getDataType: o,
  /**
   * @description: 判断数据类型是否是 string
   * @param {any} v 数据
   * @return {boolean} 是否符合
   */
  isString(t) {
    return o(t) === "string";
  },
  /**
   * @description: 判断数据类型是否是 number
   * @param {any} v 数据
   * @return {boolean} 是否符合
   */
  isNumber(t) {
    return o(t) === "number";
  },
  /**
   * @description: 判断数据类型是否是 bigint
   * @param {any} v 数据
   * @return {boolean} 是否符合
   */
  isBigint(t) {
    return o(t) === "bigint";
  },
  /**
   * @description: 判断数据类型是否是 array
   * @param {any} v 数据
   * @return {boolean} 是否符合
   */
  isArray(t) {
    return o(t) === "array";
  },
  /**
   * @description: 判断数据类型是否是 object
   * @param {any} v 数据
   * @return {boolean} 是否符合
   */
  isObject(t) {
    return o(t) === "object";
  },
  /**
   * @description: 判断数据类型是否是 symbol
   * @param {any} v 数据
   * @return {boolean} 是否符合
   */
  isSymbol(t) {
    return o(t) === "symbol";
  },
  /**
   * @description: 判断数据类型是否是 function
   * @param {any} v 数据
   * @return {boolean} 是否符合
   */
  isFunction(t) {
    return o(t) === "function";
  },
  /**
   * @description: 判断数据类型是否是 boolean
   * @param {any} v 数据
   * @return {boolean} 是否符合
   */
  isBoolean(t) {
    return o(t) === "boolean";
  },
  /**
   * @description: 判断数据类型是否是 null
   * @param {any} v 数据
   * @return {boolean} 是否符合
   */
  isNull(t) {
    return o(t) === "null";
  },
  /**
   * @description: 判断数据类型是否是 undefined
   * @param {any} v 数据
   * @return {boolean} 是否符合
   */
  isUndefined(t) {
    return o(t) === "undefined";
  },
  /**
   * @description: 判断数据类型是否是 nan
   * @param {any} v 数据
   * @return {boolean} 是否符合
   */
  isNan(t) {
    return o(t) === "nan";
  }
};
function W(t, e = "up") {
  t += 1;
  let s = "";
  for (; t > 0; ) {
    let i = t % 26;
    i = i === 0 ? i = 26 : i, s = String.fromCharCode(96 + parseInt(i)) + s, t = (t - i) / 26;
  }
  return e === "down" ? s : s.toLocaleUpperCase();
}
const E = function(t, e) {
  const s = Math.min(t, e), i = Math.max(t, e) - s;
  return i === 0 ? s : Math.floor(Math.random() * (i + 1)) + s;
}, H = {
  number: E,
  /**
   * @description: 生成随机ID
   * @return {string}
   */
  id() {
    return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
      /[xy]/g,
      function(t) {
        let e = Math.random() * 16 | 0;
        return (t === "x" ? e : e & 3 | 8).toString(16);
      }
    );
  },
  /**
   * @description: 生成随机字母
   * @param {number} count 字母长度 默认5 非必填
   * @param {"smallLetter" | "capitalization" | "mix"} type 字母类型 默认smallLetter 非必填
   * 
   * smallLetter 小写
   * 
   * capitalization 大写
   * 
   * mix 混合
   * 
   * @return {string}
   */
  english(t = 5, e = "smallLetter") {
    return Array.from({ length: t }).map(function() {
      const s = W(Math.floor(Math.random() * 26));
      return e === "capitalization" || e === "mix" && E(1, 2) === 1 ? s : s.toLocaleLowerCase();
    }).join("");
  },
  /**
   * @description: 生成随机中文
   * @param {number} count 字母长度 默认5 非必填
   * @return {string}
   */
  chinese(t = 5) {
    const e = [];
    for (let s = 0; s < t; s++) {
      let i = "";
      i = "\\u" + (Math.floor(Math.random() * (40869 - 19968)) + 19968).toString(16), i = unescape(i.replace(/\\u/g, "%u")), e.push(i);
    }
    return e.join("");
  }
};
function N(t) {
  t = t.toLocaleUpperCase();
  let e = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", s = 0;
  for (let i = 0, a = t.length - 1; i < t.length; i += 1, a -= 1)
    s += Math.pow(e.length, a) * (e.indexOf(t[i]) + 1);
  return Math.max(0, s - 1);
}
const m = ["B", "KB", "MB", "GB", "TB"];
function L(t, e = "B") {
  let s = 0;
  const i = m.indexOf(e) === -1 ? m[0] : e;
  g.isNumber(t) && t > 0 && (s = t);
  function a(r, n = 0) {
    return n = Math.floor(n), !g.isNumber(n) || !n || !(n > 0) ? Math.floor(r) : Number(r.toFixed(n));
  }
  return {
    /**
     * @description: 转换
     * @param {StorageUnit} unit 转换后的单位
     * @param {number} decimalCount 保留几位小数 默认0 非必填
     * @return {number}
     */
    convert(r, n = 0) {
      if (s <= 0)
        return 0;
      const h = m.indexOf(r) === -1 ? m[0] : r, u = m.indexOf(i), d = m.indexOf(h);
      if (u === -1 || d === -1)
        return 0;
      let b = 0;
      if (u === d)
        b = t;
      else if (u < d) {
        const p = d - u;
        for (let x = 0; x < p; x++)
          t /= 1024;
        b = t;
      } else if (u > d) {
        const p = u - d;
        for (let x = 0; x < p; x++)
          t *= 1024;
        b = t;
      }
      return n = Math.floor(n), !g.isNumber(n) || !n || !(n > 0) ? Math.floor(b) : Number(b.toFixed(n));
    },
    /**
     * @description: 自动转换
     * @param {number} decimalCount 保留几位小数 默认0 非必填
     * @return {string} 转后的值，保留存储单位
     */
    auto(r = 0) {
      if (s < 1024)
        return `${s}${i}`;
      const n = m.indexOf(i);
      for (let h = n; h > 0; h--)
        s *= 1024;
      return s < 1024 ? `${a(Math.max(0, s), r)}B` : s < 1024 * 1024 ? `${a(s / 1024, r)}KB` : s < 1024 * 1024 * 1024 ? `${a(s / 1024 / 1024, r)}MB` : s < 1024 * 1024 * 1024 * 1024 ? `${a(s / 1024 / 1024 / 1024, r)}GB` : `${a(s / 1024 / 1024 / 1024 / 1024, r)}TB`;
    }
  };
}
function D(t, e) {
  return !g.isString(t) || !t ? "" : (e = Math.max(
    -1,
    g.isNumber(e) ? Math.floor(e) : -1
  ), e <= 0 ? t : t.length > e ? t.substring(0, e) + "..." : t);
}
const F = {
  /**
   * @description: 校验内容是否是字符串，并且不为空，你也可以自定义字符串的长度范围
   * @param {any} value 内容
   * @param {number} options.min 非必传，默认1，传递时需保证大于等于1，不符合按1处理
   * @param {number} options.max 非必传，大于等于options.min即可
   * @return {*}
   */
  string(t, e) {
    if (!g.isString(t) || t === "")
      return !1;
    g.isObject(e) || (e = {});
    const s = Math.max(1, (e == null ? void 0 : e.min) || 1);
    return t.length < s ? !1 : e && e.max && g.isNumber(e.max) && e.max > s ? !(t.length > e.max) : !0;
  }
}, l = {
  version: "1.0.4",
  eventBus: T,
  queue: A,
  throttle: $,
  debounce: j,
  wait: z,
  type: g,
  random: H,
  indexToLetter: W,
  letterToIndex: N,
  storageConversion: L,
  stringEllipsis: D,
  verification: F
}, v = {
  /**
   * 透明色
   */
  transparent: "transparent",
  /**
   * 黑色
   */
  black: "#000000"
}, w = function() {
  return {
    name: "rect",
    id: "",
    rectWidth: 0,
    rectHeight: 0,
    rectX: 0,
    rectY: 0,
    base: {
      x: 0,
      y: 0,
      zIndex: 0,
      fillStyle: v.transparent,
      strokeStyle: v.black,
      strokeWidth: 0,
      lineCap: "butt",
      lineJoin: "miter",
      lineDashOffset: [0, 0],
      dragMove: !1
    },
    rect: {
      width: 0,
      height: 0
    },
    circle: {
      radius: 0
    },
    sector: {
      radius: 0,
      startAngle: 0,
      endAngle: 360
    },
    polygon: {
      radius: 0,
      sides: 0
    },
    line: {
      points: []
    },
    image: {
      width: 0,
      height: 0,
      image: ""
    },
    text: {
      text: "",
      fontSize: 12,
      bold: !1,
      italic: !1
    },
    ellipse: {
      radiusX: 0,
      radiusY: 0
    },
    star: {
      numPoints: 0,
      outerRadius: 0,
      innerRadius: 0
    },
    annular: {
      outerRadius: 0,
      innerRadius: 0,
      progress: 0,
      progressFillStyle: v.black
    },
    arc: {
      outerRadius: 0,
      innerRadius: 0,
      startAngle: 0,
      endAngle: 360
    }
  };
}, J = {
  drag(t, e) {
    t.beginPath(), t.fillRect(
      e.base.x,
      e.base.y,
      e.rect.width,
      e.rect.height
    ), e.base.strokeWidth > 0 && t.strokeRect(
      e.base.x,
      e.base.y,
      e.rect.width,
      e.rect.height
    );
  },
  calculateMatrix(t, e) {
    e.rectX = e.base.x, e.rectY = e.base.y, e.rectWidth = e.rect.width, e.rectHeight = e.rect.height;
  },
  updatePosition(t, e, s, i) {
    e.base.x = t.base.x + s, e.base.y = t.base.y + i;
  }
}, M = function(t) {
  return JSON.parse(JSON.stringify(t));
}, c = function(t) {
  return t * Math.PI / 180;
}, B = function(t, e, s = !1) {
  t.fillStyle = s ? v.black : e.base.fillStyle, t.strokeStyle = s ? v.black : e.base.strokeStyle, t.lineCap = e.base.lineCap, t.lineJoin = e.base.lineJoin, t.lineWidth = e.base.strokeWidth, t.setLineDash(s ? [] : e.base.lineDashOffset);
}, _ = function(t) {
  return Number(t.id.split("-")[0] || "-1");
}, U = {
  drag(t, e) {
    const s = e.base.x + e.circle.radius, i = e.base.y + e.circle.radius, a = c(0), r = c(360);
    t.beginPath(), t.arc(s, i, e.circle.radius, a, r), t.fill(), e.base.strokeWidth > 0 && (t.beginPath(), t.arc(s, i, e.circle.radius, a, r), t.stroke());
  },
  calculateMatrix(t, e) {
    e.rectX = e.base.x, e.rectY = e.base.y, e.rectWidth = e.circle.radius * 2, e.rectHeight = e.rectWidth;
  },
  updatePosition(t, e, s, i) {
    e.base.x = t.base.x + s, e.base.y = t.base.y + i;
  }
}, q = {
  drag(t, e) {
    const s = e.base.x + e.sector.radius, i = e.base.y + e.sector.radius, a = c(e.sector.startAngle - 90), r = c(e.sector.endAngle - 90);
    t.beginPath(), t.moveTo(s, i), t.arc(s, i, e.sector.radius, a, r), t.fill(), e.base.strokeWidth > 0 && (t.beginPath(), t.strokeStyle = e.base.strokeStyle, t.lineWidth = e.base.strokeWidth, t.moveTo(s, i), t.arc(s, i, e.sector.radius, a, r), t.lineTo(s, i), t.stroke());
  },
  calculateMatrix(t, e) {
    e.rectX = e.base.x, e.rectY = e.base.y, e.rectWidth = e.sector.radius * 2, e.rectHeight = e.rectWidth;
  },
  updatePosition(t, e, s, i) {
    e.base.x = t.base.x + s, e.base.y = t.base.y + i;
  }
}, G = {
  drag(t, e) {
    const s = e.base.x + e.polygon.radius, i = e.base.y + e.polygon.radius, a = e.polygon.radius, r = Math.max(3, e.polygon.sides);
    t.beginPath();
    for (let n = 0; n < r; n++) {
      const h = Math.PI * 2 / r * n - Math.PI / 2, u = s + a * Math.cos(h), d = i + a * Math.sin(h);
      n === 0 ? t.moveTo(u, d) : t.lineTo(u, d);
    }
    t.closePath(), t.fill(), t.stroke();
  },
  calculateMatrix(t, e) {
    e.rectX = e.base.x, e.rectY = e.base.y, e.rectWidth = e.polygon.radius * 2, e.rectHeight = e.rectWidth;
  },
  updatePosition(t, e, s, i) {
    e.base.x = t.base.x + s, e.base.y = t.base.y + i;
  }
}, K = {
  drag(t, e) {
    if (!(e.line.points.length < 0)) {
      t.beginPath(), t.moveTo(
        e.base.x,
        e.base.y - e.base.strokeWidth / 2
      );
      for (let s = 0; s < e.line.points.length; s++)
        t.lineTo(e.line.points[s].x, e.line.points[s].y);
      t.stroke();
    }
  },
  calculateMatrix(t, e) {
    const s = [e.base.x], i = [e.base.y];
    e.line.points.forEach(function(u) {
      s.push(u.x), i.push(u.y);
    });
    const a = Math.min(...s), r = Math.max(...s), n = Math.min(...i), h = Math.max(...i);
    e.rectX = a, e.rectY = n, e.rectWidth = Math.max(0, r - a), e.rectHeight = Math.max(0, h - n);
  },
  updatePosition(t, e, s, i) {
    e.base.x = t.base.x + s, e.base.y = t.base.y + i;
    for (let a = 0; a < e.line.points.length; a++)
      e.line.points[a].x = t.line.points[a].x + s, e.line.points[a].y = t.line.points[a].y + i;
  }
}, k = /* @__PURE__ */ new Map(), V = {
  drag(t, e) {
    if (!e.image.image)
      return;
    t.beginPath();
    let s = k.get(e.image.image);
    if (s) {
      t.drawImage(
        s,
        e.base.x,
        e.base.y,
        e.image.width,
        e.image.height
      );
      return;
    }
    s = new Image(), s.src = e.image.image, s.onerror = function(i) {
      console.error(
        "load image error: ",
        i,
        `
src: `,
        e.image.image
      );
    }, s.setAttribute("crossOrigin", "Anonymous"), s.onload = function() {
      k.set(e.image.image, s), t.drawImage(
        s,
        e.base.x,
        e.base.y,
        e.image.width,
        e.image.height
      );
    };
  },
  calculateMatrix(t, e) {
    e.rectX = e.base.x, e.rectY = e.base.y, e.rectWidth = e.image.width, e.rectHeight = e.image.height;
  },
  updatePosition(t, e, s, i) {
    e.base.x = t.base.x + s, e.base.y = t.base.y + i;
  }
}, I = function(t, e) {
  t.textBaseline = "top", t.font = [
    e.text.bold ? "bold" : "",
    e.text.italic ? "italic" : "",
    `${e.text.fontSize}px`,
    "Arial"
  ].join(" ");
}, Z = {
  drag(t, e) {
    const s = e.text.text;
    s && (I(t, e), t.beginPath(), t.fillText(s, e.base.x, e.base.y));
  },
  calculateMatrix(t, e) {
    I(t, e);
    const s = t.measureText(e.text.text);
    e.rectX = e.base.x, e.rectY = e.base.y - s.fontBoundingBoxAscent, e.rectWidth = s.actualBoundingBoxRight + Math.abs(s.actualBoundingBoxLeft), e.rectHeight = s.fontBoundingBoxDescent + s.fontBoundingBoxAscent;
  },
  updatePosition(t, e, s, i) {
    e.base.x = t.base.x + s, e.base.y = t.base.y + i;
  }
}, Q = {
  drag(t, e) {
    const s = e.base.x + e.ellipse.radiusX, i = e.base.y + e.ellipse.radiusY, a = c(0), r = 2 * Math.PI;
    t.beginPath(), t.ellipse(
      s,
      i,
      e.ellipse.radiusX,
      e.ellipse.radiusY,
      a,
      0,
      r
    ), t.fill(), e.base.strokeWidth > 0 && (t.beginPath(), t.ellipse(
      s,
      i,
      e.ellipse.radiusX,
      e.ellipse.radiusY,
      a,
      0,
      r
    ), t.stroke());
  },
  calculateMatrix(t, e) {
    e.rectX = e.base.x, e.rectY = e.base.y, e.rectWidth = e.ellipse.radiusX * 2, e.rectHeight = e.ellipse.radiusY * 2;
  },
  updatePosition(t, e, s, i) {
    e.base.x = t.base.x + s, e.base.y = t.base.y + i;
  }
}, ee = {
  drag(t, e) {
    t.beginPath();
    const s = Math.max(5, e.star.numPoints), i = e.base.x + e.star.outerRadius, a = e.base.y + e.star.outerRadius;
    for (let r = 0; r < s * 2; r++) {
      const n = r % 2 === 0 ? e.star.outerRadius : e.star.innerRadius;
      t.lineTo(
        i + Math.cos(Math.PI * 2 * (r / s + 126 / 360)) * n,
        a + Math.sin(Math.PI * 2 * (r / s + 126 / 360)) * n
      );
    }
    t.closePath(), e.base.strokeWidth > 0 && (t.lineWidth = e.base.strokeWidth * 2), t.stroke(), t.fill();
  },
  calculateMatrix(t, e) {
    e.rectX = e.base.x, e.rectY = e.base.y, e.rectWidth = e.star.outerRadius * 2, e.rectHeight = e.rectWidth;
  },
  updatePosition(t, e, s, i) {
    e.base.x = t.base.x + s, e.base.y = t.base.y + i;
  }
}, te = {
  drag(t, e) {
    const s = e.base.x + e.annular.outerRadius, i = e.base.y + e.annular.outerRadius, a = c(0), r = c(360), n = Math.min(100, Math.max(0, e.annular.progress)), h = e.base.strokeWidth, u = e.base.strokeStyle, d = e.base.fillStyle;
    t.beginPath(), t.lineWidth = e.annular.outerRadius - e.annular.innerRadius, t.strokeStyle = d, t.arc(
      s,
      i,
      e.annular.innerRadius + t.lineWidth / 2,
      a,
      r
    ), t.stroke(), n > 0 && (t.beginPath(), t.strokeStyle = e.annular.progressFillStyle, t.arc(
      s,
      i,
      e.annular.innerRadius + t.lineWidth / 2,
      c(-90),
      c(n / 100 * 360 - 90)
    ), t.stroke()), h > 0 && (t.strokeStyle = u, t.lineWidth = h, t.beginPath(), t.arc(s, i, e.annular.outerRadius, a, r), t.stroke(), t.beginPath(), t.arc(s, i, e.annular.innerRadius, a, r), t.stroke());
  },
  calculateMatrix(t, e) {
    e.rectX = e.base.x, e.rectY = e.base.y, e.rectWidth = e.annular.outerRadius * 2, e.rectHeight = e.rectWidth;
  },
  updatePosition(t, e, s, i) {
    e.base.x = t.base.x + s, e.base.y = t.base.y + i;
  }
}, se = {
  drag(t, e) {
    const s = e.base.x + e.arc.outerRadius, i = e.base.y + e.arc.outerRadius, a = c(e.arc.startAngle - 90), r = c(e.arc.endAngle - 90);
    t.beginPath(), t.arc(s, i, e.arc.outerRadius, a, r, !1), t.arc(s, i, e.arc.innerRadius, r, a, !0), t.closePath(), t.fill(), t.stroke();
  },
  calculateMatrix(t, e) {
    e.rectX = e.base.x, e.rectY = e.base.y, e.rectWidth = e.arc.outerRadius * 2, e.rectHeight = e.rectWidth;
  },
  updatePosition(t, e, s, i) {
    e.base.x = t.base.x + s, e.base.y = t.base.y + i;
  }
}, R = {
  rect: J,
  circle: U,
  sector: q,
  polygon: G,
  line: K,
  image: V,
  text: Z,
  ellipse: Q,
  star: ee,
  annular: te,
  arc: se
};
class S {
  /**
   * 初始化
   */
  constructor(e) {
    this.canvasElement = document.createElement("canvas"), e.appendChild(this.canvasElement), this.context = this.canvasElement.getContext("2d", {
      willReadFrequently: !0
    });
  }
  /**
   * 更新矩阵信息
   */
  updateRectInfo(e) {
    this.canvasElement.style.setProperty("pointer-events", "none"), this.canvasElement.style.setProperty("position", "absolute"), this.canvasElement.style.setProperty("top", "0"), this.canvasElement.style.setProperty("left", "0"), this.canvasElement.style.setProperty(
      "width",
      e.offsetWidth + "px"
    ), this.canvasElement.style.setProperty(
      "height",
      e.offsetHeight + "px"
    ), this.canvasElement.width = e.offsetWidth * window.devicePixelRatio, this.canvasElement.height = e.offsetHeight * window.devicePixelRatio;
  }
  /**
   * 销毁
   */
  destruction() {
    this.canvasElement.remove();
  }
}
function ie(t, e, s, i, a, r) {
  return r.filter(function(n) {
    return a.clearRect(0, 0, t, e), B(a, n, !0), R[n.name].drag(a, n), (n.name === "text" || n.name === "image") && (a.beginPath(), a.fillRect(
      n.rectX,
      n.rectY,
      n.rectWidth,
      n.rectHeight
    )), a.getImageData(s, i, 1, 1).data[3] !== 0;
  }).reverse()[0] || null;
}
const y = "hxzx-canvas";
class ne {
  /**
   * @description: 初始化
   * @param {string} selectors 绘制容器信息
   * @param {number} config.frameRate 帧率，默认60帧，最低10，最高120
   */
  constructor(e, s = {}) {
    /**
     * 库名
     */
    f(this, "name", y);
    /**
     * 控件
     */
    f(this, "_controlMap", /* @__PURE__ */ new Map());
    /**
     * 控件累计数
     */
    f(this, "_controlCount", 0);
    /**
     * 宽度
     */
    f(this, "width", 0);
    /**
     * 高度
     */
    f(this, "height", 0);
    /**
     * 当前选择的控件
     */
    f(this, "selectControlId", "");
    /**
     * 帧率
     */
    f(this, "frameRate", 0);
    try {
      if (!e || typeof e != "string")
        throw "错误的选择器" + e;
      const n = document.querySelector(e);
      if (!n) {
        console.error("未找到对应的容器", e);
        return;
      }
      this._containerElement = n;
    } catch (n) {
      console.error(n);
      return;
    }
    this.frameRate = 1e3 / Math.min(
      120,
      Math.max(10, Math.max(0, parseInt(String(s.frameRate || "60"))))
    ), this.drag = l.throttle(() => {
      if (console.time("drag"), this._stage.updateRectInfo(this._containerElement), this._stageBehind.updateRectInfo(this._containerElement), this.width = this._containerElement.offsetWidth, this.height = this._containerElement.offsetHeight, this._stage.context.clearRect(0, 0, this.width, this.height), this._stage.context.scale(
        window.devicePixelRatio,
        window.devicePixelRatio
      ), this._controlSort("drag").forEach((n) => {
        const h = R[n.name];
        B(this._stage.context, n), h.calculateMatrix(this._stage.context, n), h.drag(this._stage.context, n);
      }), this.selectControlId) {
        const n = this._controlMap.get(this.selectControlId);
        n && (this._stage.context.beginPath(), this._stage.context.lineWidth = 1, this._stage.context.strokeStyle = "#409eff", this._stage.context.strokeRect(
          n.rectX,
          n.rectY,
          n.rectWidth,
          n.rectHeight
        ));
      }
      console.timeEnd("drag");
    }, this.frameRate), this._containerElement.style.setProperty("box-sizing", "border-box"), this._containerElement.style.setProperty("position", "relative"), this._containerElement.style.setProperty("overflow", "hidden"), this._stage = new S(this._containerElement), this._stageBehind = new S(this._containerElement), this._stageBehind.canvasElement.style.setProperty("opacity", "0"), window.addEventListener("resize", this.drag), this._containerResizeObserver = new ResizeObserver(this.drag), this._containerResizeObserver.observe(this._containerElement), this._containerElement.onclick = this._createEvent("click"), this._containerElement.oncontextmenu = this._createEvent("contextmenu");
    let i = 0, a = 0;
    this._containerElement.onmousedown = this._createEvent(
      "mousedown",
      (n) => {
        this.selectControlId = "";
        const h = this._controlMap.get(n.controlId);
        if (h) {
          const u = M(h);
          this.selectControlId = h.id, i = n.pageX, a = n.pageY;
          const d = (p) => {
            R[h.name].updatePosition(
              u,
              h,
              p.pageX - i,
              p.pageY - a
            ), this.drag();
          }, b = function() {
            document.removeEventListener("mousemove", d), document.removeEventListener("mouseup", b);
          };
          document.addEventListener("mousemove", d), document.addEventListener("mouseup", b);
        }
        this.drag();
      }
    );
    let r = "";
    this._containerElement.onmousemove = this._createEvent(
      "mousemove",
      function(n) {
        n.controlId && !r && (n.name = "mouseenter", l.eventBus.emit(
          [y, n.name].join("-"),
          n
        ), r = n.controlId), n.controlId !== r && r && (n.controlId = r, n.name = "mouseleave", l.eventBus.emit(
          [y, n.name].join("-"),
          n
        ), r = "");
      }
    ), this._containerElement.onmouseup = this._createEvent("mouseup"), this._containerElement.onmouseleave = this._createEvent("mouseleave"), this._containerElement.onmouseenter = this._createEvent("mouseenter");
  }
  /**
   * 创建事件
   */
  _createEvent(e, s) {
    return (i) => {
      i.preventDefault();
      const a = i.offsetX, r = i.offsetY, n = {
        name: e,
        button: i.button,
        screenX: i.screenX,
        screenY: i.screenY,
        clientX: i.clientX,
        clientY: i.clientY,
        pageX: i.pageX,
        pageY: i.pageY,
        offsetX: a,
        offsetY: r,
        scrollX: 0,
        scrollY: 0,
        width: this.width,
        height: this.height,
        controlId: ""
      };
      if (e !== "mouseleave") {
        const h = ie(
          this.width,
          this.height,
          a,
          r,
          this._stageBehind.context,
          this._controlSort("stageBehind")
        );
        h && (n.controlId = h.id);
      }
      l.eventBus.emit([y, e].join("-"), n), s && s(n);
    };
  }
  /**
   * 控件列表排序
   */
  _controlSort(e) {
    return Array.from(this._controlMap.values()).sort(function(s, i) {
      return e === "stageBehind" || e === "drag" ? s.base.zIndex < i.base.zIndex ? -1 : s.base.zIndex > i.base.zIndex ? 1 : _(s) - _(i) : 1;
    });
  }
  /**
   * 添加控件
   */
  addControl(e, s, i) {
    const a = w();
    return a.name = e, a.id = [this._controlCount, l.random.id()].join(
      "-"
    ), Object.assign(a.base, s), Object.assign(a[e], i), this._controlMap.set(a.id, a), this._controlCount++, a.id;
  }
  /**
   * 根据ID删除控件
   */
  removeControlById(e) {
    (l.type.isArray(e) ? Array.from(e) : [String(e)]).forEach((i) => {
      this._controlMap.delete(i);
    }), this.drag();
  }
  /**
   * 根据ID获取控件
   */
  getControlById(e) {
    const s = this._controlMap.get(e);
    return s === void 0 ? null : s;
  }
  /**
   * 根据ID编辑控件
   */
  editControlById(e, s, i) {
    const a = this._controlMap.get(e);
    if (a) {
      if (a.base.hasOwnProperty(s)) {
        a.base[s] = i;
        return;
      }
      if (a[a.name].hasOwnProperty(s)) {
        a[a.name][s] = i;
        return;
      }
    }
  }
  /**
   * 订阅
   */
  on(e, s) {
    l.eventBus.on([y, e].join("-"), s);
  }
  /**
   * 取消订阅
   */
  off(e, s) {
    l.eventBus.off([y, e].join("-"), s);
  }
  /**
   * 导出数据
   */
  exportData() {
    return M(this._controlSort("default"));
  }
  /**
   * 导入数据
   */
  importData(e) {
    this._controlMap.clear(), this._controlCount = 0, M(e).forEach((s) => {
      const i = Object.assign(w(), s), a = _(i);
      if (console.log(i, a), !l.type.isNumber(a) || a < 0 || !(/^0*[1-9]\d*$/.test(String(a)) || /^0*$/.test(String(a)))) {
        console.error("该控件导入失败，ID错误", i);
        return;
      }
      this._controlMap.set(i.id, i), this._controlCount = Math.max(
        this._controlCount,
        _(i)
      );
    });
  }
  /**
   * @description: 销毁
   * @return {*}
   */
  destruction() {
    window.removeEventListener("resize", this.drag), this._containerResizeObserver.disconnect(), this._stage.destruction(), this._stageBehind.destruction();
  }
}
export {
  ne as default
};
